#include <stdio.h>
#include <malloc.h>

struct cell { //��������ṹ�嶨��
    int x;
    struct cell *next;
};

struct cell *build(void) { //�½��������������õĵ������׽���ַ����
    struct cell *head, *tmp, *p;
    head = tmp = p = NULL;
    int n;
    head = (struct cell *) malloc(sizeof(struct cell));
    scanf("%d", &head->x);
    tmp = head;
    tmp->next = NULL;
    if (head->x == 0) head = NULL;
    else {
        do {
            p = (struct cell *) malloc(sizeof(struct cell));
            scanf("%d", &p->x);
            tmp->next = p;
            tmp = p;
            tmp->next = NULL;
        } while (p->x != 0);
    }
    return head;//���ص�����ͷ
}

void print(struct cell *head)//��ӡ����������,head��ָ�������׽���ָ��
{
    struct cell *p;
    printf("%d", head->x);
    p = head->next;
    while (p->x != 0) {
        printf(" %d", p->x);
        p = p->next;
    }
}

void release(struct cell *head) //�ͷŵ�����ռ�,head��ָ�������׽���ָ��
{
    struct cell *p;
    while (head != NULL) {
        p = head;
        head = p->next;
        free(p);
    }
}

int main(void) {
    struct cell *head;
    head = build();
    if (head != NULL) {
        print(head);
    } else {
        printf("NULL");
    }
    release(head);
}
